clear all
version 16.1
set type double
/* delta_s is the running variable */
do "modules/__drawgraph.do"
do "modules/rdbwselect2a.ado"
graph drop _all

/* setttings (common) */
local id = ""
local st_fy = "2011"
local en_fy = "."
local msz = "medsmall"
local graphtableop = "onebw; nofit"
local bwselector =  "msetwo"
local color01 = ""
local nquantiles = 50	
pause on
foreach type in "s" "p" {
	/* Treatment*/
	use ../tmp/sample_090122.dta, clear
	set type double
	cap drop thebidder
	cap graph drop treatment_`type'
	if "`type'" == "s"{
		qui gen thebidder = 1 if firm_treatment == 1 & ftt_ts1s > 1.65 & ftt_ts1s < . /*& fy_con != 2020*/
	}
	else{
		qui gen thebidder = 1 if firm_treatment == 1 & ftt_ts1p < -1.65 /*& fy_con != 2020*/
	}
	*Before
	local gname = "left"
	local gtitle = "Before"
	local st_mdybid  = "td(01apr2015)"
	local ed_mdybid = "td(15feb2019)"
	rddelta1x_binscatter_`type' "`id'" "`st_fy'" "`en_fy'" "`gname'" "`gtitle'" "`msz'" "`st_mdybid'" ///
		"`ed_mdybid'" "`graphtableop'" "`bwselector'" "`color01'" "`nquantiles'"
	*pause
	*After 
	local gname = "right"
	local gtitle = "After"
	local st_mdybid  = "td(15mar2019)" 
	local ed_mdybid = "td(31mar2021)"
	rddelta1x_binscatter_`type' "`id'" "`st_fy'" "`en_fy'" "`gname'" "`gtitle'" "`msz'" "`st_mdybid'" ///
		"`ed_mdybid'" "`graphtableop'" "`bwselector'" "`color01'" "`nquantiles'"

	graph combine left right, xsize(6) ysize(4) graphregion(c(white)) /*note("by `endpd'", size(vsmall))*/ ///
		title("Treatment", size(medlarge)) scale(1.1) imargin(small) name(treatment_`type')
	graph export "../graph/binscatter_Treatmentfirms_`type'_by`endpd'.png", as(png) width(4096) replace

	/*Control*/
	use ../tmp/sample_090122.dta, clear
	set type double
	cap drop thebidder
	cap graph drop control_`type'
	if "`type'" == "s"{
		gen thebidder = 1 if firm_treatment == 0 & ftt_ts1s > 1.65 & ftt_ts1s <. & g28_plus != 21 & g28_plus != 24 
	}
	else{
		gen thebidder = 1 if firm_treatment == 0 & g28_plus != 21 & g28_plus != 24 & ftt_ts1p < -1.65
	}
	*Before
	local gname = "left"
	local gtitle = "Before"
	local st_mdybid  = "td(01apr2015)"
	local ed_mdybid = "td(15feb2019)"
	rddelta1x_binscatter_`type' "`id'" "`st_fy'" "`en_fy'" "`gname'" "`gtitle'" "`msz'" "`st_mdybid'" ///
		"`ed_mdybid'" "`graphtableop'" "`bwselector'" "`color01'" "`nquantiles'"
	*After
	local gname = "right"
	local gtitle = "After"
	local st_mdybid  = "td(15mar2019)" 
	local ed_mdybid = "td(31mar2021)"
	rddelta1x_binscatter_`type' "`id'" "`st_fy'" "`en_fy'" "`gname'" "`gtitle'" "`msz'" "`st_mdybid'" ///
		"`ed_mdybid'" "`graphtableop'" "`bwselector'" "`color01'" "`nquantiles'"
	graph combine left right, xsize(6) ysize(4) graphregion(c(white)) /*note("by `endpd'", size(vsmall))*/ ///
		title("Control", size(medlarge)) scale(1.1) imargin(small) name(control_`type')
	graph export "../graph/binscatter_Controlfirms_`type'_by`endpd'.png", as(png) width(4096) replace
}
	
	